﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace AssetManageSystem.Model
{
    public class Helper
    {
        /// <summary>
        /// 生成部分表的流水单号(调拨单、报废单、报修单)
        /// </summary>
        /// <param name="Head"></param>
        /// <param name="MaxID"></param>
        /// <returns></returns>
        public static String GeneratePRID(String Head, String MaxID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(Head);
            if (String.IsNullOrWhiteSpace(MaxID))
            {
                sb.Append("000000001");
            }
            else
            {
                int HeadLength = Head.Length;
                int MinuteMax = int.Parse(MaxID.Substring(HeadLength, 9));
                String NowMax = (MinuteMax + 1).ToString();
                for (int i = 0; i < 10 - NowMax.Length - HeadLength; i++)
                {
                    sb.Append("0");
                }
                sb.Append(NowMax);
            }
            return sb.ToString();
        }
        /// <summary>
        /// 根据日期时间生成流水单号
        /// </summary>
        public class RandomNumber
        {
            public static object _lock = new object();
            public static int count = 1;

            public static string GetRandom()
            {
                lock (_lock)
                {
                    if (count >= 10000)
                    {
                        count = 1;
                    }
                    var number = DateTime.Now.ToString("yyyyMMddHHmmss") + count.ToString("0000");
                    count++;
                    return number;
                }
            }
        }

    }
}